define('component/wxUtils', [], function () {
  var setTagNavListInLocalstorage = function (list) {
    localStorage.tagNaveList = JSON.stringify(list)
  }
  // 其中的每个元素只包含路由原信息中的name, path, meta三项

  var getTagNavListFromLocalstorage = function () {
    var list = localStorage.tagNaveList
    return list ? JSON.parse(list) : []
  }

  var getHomeRoute = function (routers) {
    let i = -1
    let len = routers.length
    let homeRoute = {}
    while (++i < len) {
      let item = routers[i]
      if (item.children && item.children.length) {
        let res = getHomeRoute(item.children)
        if (res.meta.homepage) return res
      } else {
        if (item.meta.homepage) homeRoute = item
      }
    }
    return homeRoute
  }

  var showTitle = function (item) {
    // console.log(item)
    return ((item.meta && item.meta.title) || item.name)
  }

  var getNewTagList = function (list, newRoute) {
    const { name, path, meta } = newRoute
    let newList = [...list]
    if (newList.findIndex(item => item.name === name) >= 0) return newList
    else newList.push({ name, path, meta})
    return newList
  }

  var getNextName = function (list, name) {
    let res = ''
    // console.log(name)
    // console.log(list)
    if (list.length === 2) {
      res = 'home'
    } else {
      if (list.findIndex(item => item.name === name) === list.length - 1) res = list[list.length - 2].name
      else res = list[list.findIndex(item => item.name === name) + 1].name
    }
    return res
  }

  return {
    getHomeRoute,
    setTagNavListInLocalstorage,
    getTagNavListFromLocalstorage,
    showTitle,
    getNewTagList,
  getNextName}
})
